//! \file user.hpp
//! \brief Purewell Library User Header
//! \author Yubin Lim (purewell@gmail.com)
//! \since 2008-11-02

#ifndef __PWHDR_USER_HPP__
#define __PWHDR_USER_HPP__

#include <string>
#include <list>

namespace purewell
{

class PWGroup;

//! \brief User information.
class PWUser
{
public:
	//! \brief Get user information from password database.
	//! \param[in] uid UID.
	//! \return On success, true.
	bool getUser(uid_t uid);

	//! \brief Get user information from password database.
	//! \param[in] id User ID.
	//! \return On success, true.
	bool getUser(const char* id);

	//! \brief Get user id.
	//! \return User ID.
	inline const char* getID(void) const
	{
		return m_id.c_str();
	}

	//! \brief Get user password.
	//! \return User password.
	inline const char* getPassword(void) const
	{
		return m_password.c_str();
	}

	//! \brief Get UID.
	//! \return UID.
	inline uid_t getUID(void) const
	{
		return m_uid;
	}

	//! \brief Get GID.
	//! \return GID.
	inline gid_t getGID(void) const
	{
		return m_gid;
	}

	//! \brief Get name.
	//! \return Name.
	inline const char* getName(void) const
	{
		return m_name.c_str();
	}

	//! \brief Get home directory.
	//! \return Home directory.
	inline const char* getHomeDirectory(void) const
	{
		return m_homedir.c_str();
	}

	//! \brief Get shell path.
	//! \return Shell path.
	inline const char* getShell(void) const
	{
		return m_shell.c_str();
	}

public:
	PWUser();
	virtual ~PWUser();

private:
	std::string	m_id;
	std::string	m_password;
	uid_t		m_uid;
	gid_t		m_gid;
	std::string	m_name;
	std::string	m_homedir;
	std::string	m_shell;
};

//! \brief Group information.
class PWGroup
{
public:
	//! \brief User container.
	typedef std::list<std::string>		user_cont;

	//! \brief Iterator of user container.
	typedef user_cont::iterator			user_itr;

	//! \brief Constant iterator of user container.
	typedef user_cont::const_iterator	user_citr;

public:
	//! \brief Get group information.
	//! \param[in] gid GID
	//! \return On success, true.
	bool getGroup(gid_t gid);

	//! \brief Get group information.
	//! \param[in] id Group ID.
	//! \return On success, true.
	bool getGroup(const char* id);

	//! \brief Get group id.
	//! \return Group ID.
	inline const char* getID(void) const
	{
		return m_id.c_str();
	}

	//! \brief Get group password.
	//! \return Group password.
	inline const char* getPassword(void) const
	{
		return m_password.c_str();
	}

	//! \brief Get GID.
	//! \return GID.
	inline uid_t getGID(void) const
	{
		return m_gid;
	}

	//! \brief Get members.
	//! \return Member container reference.
	inline user_cont& getUsers(void)
	{
		return m_users;
	}

	//! \brief Get members.
	//! \return Member container reference.
	inline const user_cont& getUsers(void) const
	{
		return m_users;
	}

public:
	PWGroup();
	virtual ~PWGroup();

private:
	std::string	m_id;
	std::string	m_password;
	gid_t		m_gid;
	user_cont	m_users;
};

};//namespace purewell

#endif//!__PWHDR_USER_HPP__

